package com.cpi.cornpp.corntypes.converter;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.cpi.cornpp.common.exception.CornPPException;
import com.cpi.cornpp.corntypes.dto.CornTypesDTO;
import com.cpi.cornpp.corntypes.exception.CornTypesException;
import com.cpi.cornpp.corntypes.view.CornTypesView;
/**
 * Corn Types Converter
 * 
 * @author Edgar Joao
 * 
 */
public class CornTypesConverter {
	/**
	 * Corn Types Converter DTO to View
	 * @author Edgar Joao
	 * 
	 * @param dto
	 * @return
	 * @throws CornTypesException
	 */
	public CornTypesView converterCornTypesDtoToView(CornTypesDTO dto) throws CornTypesException{
		CornTypesView view = null;
		try{
			if(dto != null){
				view = new CornTypesView();
				view.setCornTypeId(dto.getCornTypeId());
				view.setCode(StringUtils.trim(dto.getCode()));
				view.setDescription(StringUtils.trim(dto.getDescription()));
			}
		}catch( Exception exception ){
			CornTypesException conrCornTypesException=null;
			exception.printStackTrace(System.out);
			conrCornTypesException= new CornTypesException(exception , CornPPException.LAYER_CONVERTER,CornPPException.ACTION_LISTS);
			throw conrCornTypesException;
		}
		return view;
	}
	/**
	 * List Corn Types Converter DTO to View
	 * 
	 * @author Edgar Joao
	 * @param cornsTypesDTOs
	 * @return
	 * @throws CornTypesException
	 */
	public List convertDTOsToViews(List cornsTypesDTOs) throws CornTypesException {
		List cornsTypesViews = null;
		Iterator iterator = null;
		CornTypesDTO dto = null;
		CornTypesView view = null;
		try{
			cornsTypesViews = new ArrayList(0);
			iterator = cornsTypesDTOs.iterator();
			while(iterator.hasNext()){
				dto = (CornTypesDTO) iterator.next();
				view = this.converterCornTypesDtoToView(dto);
				cornsTypesViews.add(view);				
			}			
		}catch(Exception exception){
			CornTypesException cornTypesException=null;
			exception.printStackTrace(System.out);
			cornTypesException= new CornTypesException(exception , CornPPException.LAYER_CONVERTER,CornPPException.ACTION_LISTS);
			throw cornTypesException;
		}
		return cornsTypesViews;
	}
}
